var express = require('express');
var app = express();
var bodyParser = require('body-parser');//用于req.body获取值的
// 处理静态资源
app.use(express.static('public'))
// 处理参数
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
//  ------------------
//  这个文件时在学习vue的前端交互时用于测试的
// -------------------

// app.get('*', function (req, res, next) {
//   res.header("Access-Control-Allow-Origin", "*");
//   res.header("Access-Control-Allow-Methods", "PUT,GET,POST,DELETE,OPTIONS");
//   res.header("Access-Control-Allow-Headers", "X-Requested-With");
//   res.header("Access-Control-Allow-hEADERS", "Content-Type");
//   next();
// });

app.get('/', function (req, res) {
  res.send('hello world');
});

app.get('/table2', function (req, res) {
  res.header("Access-Control-Allow-Origin", "*");
  res.json([
    {    
      id: 6,
      name: "lisi",
      price: "123"
    }, {
      id: 2,
      name: "wangwu",
      price: "674"
    }, {
      id: 3,
      name: "zhangsan",
      price: "436"
    }, {
      id: 4,
      name: "holle",
      price: "34"
    }, {
      id: 5,
      name: "djie"
    },
    {    
      id: 6,
      name: "lisi",
      price: "123"
    }, {
      id: 2,
      name: "wangwu",
      price: "674"
    }, {
      id: 3,
      name: "zhangsan",
      price: "436"
    }, {
      id: 4,
      name: "holle",
      price: "34"
    }, {
      id: 5,
      name: "djie"
    },
    {    
      id: 6,
      name: "lisi",
      price: "123"
    }, {
      id: 2,
      name: "wangwu",
      price: "674"
    }, {
      id: 3,
      name: "zhangsan",
      price: "436"
    }, {
      id: 4,
      name: "holle",
      price: "34"
    }, {
      id: 5,
      name: "djie"
    },
    {    
      id: 6,
      name: "lisi",
      price: "123"
    }, {
      id: 2,
      name: "wangwu",
      price: "674"
    }, {
      id: 3,
      name: "zhangsan",
      price: "436"
    }, {
      id: 4,
      name: "holle",
      price: "34"
    }, {
      id: 5,
      name: "djie"
    },
    {    
      id: 6,
      name: "lisi",
      price: "123"
    }, {
      id: 2,
      name: "wangwu",
      price: "674"
    }, {
      id: 3,
      name: "zhangsan",
      price: "436"
    }, {
      id: 4,
      name: "holle",
      price: "34"
    }, {
      id: 5,
      name: "djie"
    },
    {    
      id: 6,
      name: "lisi",
      price: "123"
    }, {
      id: 2,
      name: "wangwu",
      price: "674"
    }, {
      id: 3,
      name: "zhangsan",
      price: "436"
    }, {
      id: 4,
      name: "holle",
      price: "34"
    }, {
      id: 5,
      name: "djie"
    },
    {    
      id: 6,
      name: "lisi",
      price: "123"
    }, {
      id: 2,
      name: "wangwu",
      price: "674"
    }, {
      id: 3,
      name: "zhangsan",
      price: "436"
    }, {
      id: 4,
      name: "holle",
      price: "34"
    }, {
      id: 5,
      name: "djie"
    }
  ])
  console.log('ok',req.query)
});






app.listen(3002, function () {
  console.log('访问```：127.0.0.1:3002');
});